import urllib.request

url = 'http://httpbin.org/ip'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36'
    #'cookie':'BIDUPSID=2E47CE0E865DA08208594E951DDA03FD; PSTM=1755478323; BAIDUID=2E47CE0E865DA082B5D43ACA96F2A2A7:FG=1; BD_UPN=12314753; BAIDUID_BFESS=2E47CE0E865DA082B5D43ACA96F2A2A7:FG=1; ZFY=G1Kjn6:BcwicPboe:BoYzVpG5AqTPFR5w3ICOlF:BzfYbw:C; H_PS_PSSID=62325_63148_63324_63948_64049_64174_64247_64330_64360_64365_64361_64364_64395_64417_64430_64436_64450_64457_64473_64484_64514_64087_64562_64564_64574_64590_64595_64598_64601_64615; delPer=0; BD_CK_SAM=1; PSINO=1; H_PS_645EC=5428P1SsksiwFlZ5gv4g0EO8a1n6a%2Bu1QFId8%2BQSXU0jD5J%2Bf%2BGkZITzKYM; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BA_HECTOR=80008l840k8k2g248484052404a42i1kaa61625; baikeVisitId=7035ef0c-e676-4d89-8f70-757dd6bab70e; H_WISE_SIDS=62325_63148_63324_63948_64049_64174_64247_64330_64360_64365_64361_64364_64395_64417_64430_64436_64450_64457_64473_64484_64514_64087_64562_64564_64574_64590_64595_64598_64601_64615; COOKIE_SESSION=0_0_1_1_0_0_1_0_1_0_0_0_0_0_0_0_0_0_1755650086%7C1%230_0_1755650086%7C1'
}

# 请求对象的定制
request = urllib.request.Request(url = url,headers= headers)

# 模拟浏览器访问服务器
# response = urllib.request.urlopen(request)

proxies = {
    'http': 'http://118.178.197.213:3128'
}
# handler  build_opener  open
handler = urllib.request.ProxyHandler(proxies = proxies)

opener = urllib.request.build_opener(handler)

response = opener.open(request)

# 获取响应的信息
content = response.read().decode('utf-8')

# 保存
with open('daili.html','w',encoding='utf-8')as fp:
    fp.write(content)

